using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace CUtil
{
	/// <summary>
	/// Summary description for CollectionUtils.
	/// </summary>
	public class CollectionUtils
	{
		public CollectionUtils()
		{
			//
			// TODO: Add constructor logic here
			//
		}
        public static IList<string> SortListOfStrings(IList<string> listOfStrings)
        {
            SortedList sortedList = new SortedList();
            for (int i = 0; i < listOfStrings.Count; i++)
            {
                object c = listOfStrings[i];
                if (!sortedList.ContainsValue(c))
                    sortedList.Add(c.ToString(), c);
            }
            listOfStrings = new List<string>();
            for (int i = 0; i < sortedList.Count; i++)
            {
                string c = sortedList.GetByIndex(i) as string;
                listOfStrings.Add(c);
            }
            return listOfStrings;

            
        }
		public static ArrayList SortArrayList(ArrayList arrList)
		{
			try
			{
				SortedList sortedList = new SortedList();
				for (int i = 0; i < arrList.Count; i++)
				{
					object c = arrList[i];
					if(!sortedList.ContainsValue(c))
                        sortedList.Add(c.ToString(), c);
				}
				arrList = new ArrayList();
				for (int i = 0; i < sortedList.Count; i++)
				{
					object c = sortedList.GetByIndex(i);
					arrList.Add(c);
				}

			}
			catch(Exception exc)
			{
				Debug.Assert(false, "Error sorting array list", exc.Message);

			}
			return arrList;

		}
    

		/// <summary>
		///Helper class for CreateAvailableCategoryList
		/// </summary>
		public static NameObjectCollection ExpandNameObjectCollections(NameObjectCollection col1,NameObjectCollection col2)
		{
		
			NameObjectCollection colResult = new NameObjectCollection();

			try
			{
				//if (col1 == null) then expand the list with the col2 !! 
				if( col2 == null)
					return col1;
				if(col1 == null)
					col1 = new NameObjectCollection();
				for(int i = 0; i < col1.Count; i ++ )
				{
					colResult.Add(col1.Keys[i],col1[i]);
				}

			
				
				for(int i = 0; i < col2.Count; i ++ )
				{
					if(! (col2.Keys[i] == null) )
					{
						if(! colResult.Contains(col2.Keys[i]))
							colResult.Add(col2.Keys[i],col2[i]);
					}
				}
			
				return colResult;
			}
			catch(Exception e)
			{
				System.Diagnostics.Debug.Assert(false,"PropertyView: error in ExpandNameObjectCollections " + e.Message);
				return colResult;
			}
		}
	}
}
